//
//  ESTDataAnalyseViewController.m
//  ESTSCRMAPP
//
//  Created by 李贤立 on 2018/11/2.
//  Copyright © 2018年 Capfer. All rights reserved.
//

#import "ESTDataAnalyseViewController.h"

@interface ESTDataAnalyseViewController ()<UITableViewDelegate, UITableViewDataSource>
/**
 *  TableView
 */
@property(nonatomic, strong) TYZTableView *tableView;
/**
 *  数据源
 */
@property(nonatomic, strong) NSArray<NSArray<NSArray<NSString *> *> *> *dataArray;
@end

@implementation ESTDataAnalyseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupTitleView];
    [self setupTableView];
}
- (void)setupTitleView {
    TYZView *titleView = [[TYZView alloc] init];
    [self.view addSubview:titleView];
    [titleView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.equalTo(self.view);
        make.height.mas_equalTo(DE_NavigationHeight);
    }];
    titleView.backgroundColor = ThemeColor;
    TYZLabel *titleLabel = [[TYZLabel alloc] init];
    [titleView addSubview:titleLabel];
    [titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(titleView);
        make.bottom.equalTo(titleView).offset(-10);
    }];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.text = [@"数据分析" S];
    titleLabel.font = [UIFont boldSystemFontOfSize:CoreInfo.fontSize * 1.2];
    titleLabel.textColor = TYZWhiteColor;
}
- (void)setupTableView {
    [self.view addSubview:self.tableView];
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.bottom.equalTo(self.view);
        make.top.equalTo(self.view).offset(DE_NavigationHeight);
    }];
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"ESTDataAnalyseViewControllerCell"];
}
#pragma mark - UITableViewDelegate, UITableViewDataSource
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.section < 2) {
        if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
            [cell setSeparatorInset:UIEdgeInsetsZero];
        }
        if ([cell respondsToSelector:@selector(setLayoutMargins:)]) {
            [cell setLayoutMargins:UIEdgeInsetsZero];
        }
        if([cell respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
            [cell setPreservesSuperviewLayoutMargins:NO];
        }
    }
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return self.dataArray.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.dataArray[section].count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    if (section == 0) {
        return 0;
    }
    return Value_Height_PartPadding;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    TYZView *view = [[TYZView alloc] init];
    view.backgroundColor = ESTBackgroundColor;
    return view;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ESTDataAnalyseViewControllerCell" forIndexPath:indexPath];
    NSArray *arr = self.dataArray[indexPath.section][indexPath.row];
    cell.imageView.image = [UIImage imageNamed:arr.firstObject];
    cell.textLabel.text = arr.lastObject;
    cell.textLabel.textColor = TYZBlackColor;
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    if (indexPath.section == 2) {// 最后一行
        cell.separatorInset = UIEdgeInsetsMake(0, 0, 0, kWindowWidth);
    }
    return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}
#pragma mark - setter & getter
- (TYZTableView *)tableView {
    if (_tableView == nil) {
        _tableView = [[TYZTableView alloc] init];
        _tableView.delegate = self;
        _tableView.dataSource = self;
    }
    return _tableView;
}
- (NSArray<NSArray<NSArray<NSString *> *> *> *)dataArray {
    if (_dataArray == nil) {
        _dataArray = @[
                       @[@[@"data_analyse_table", [@"工作一览表" S]]],
                       @[@[@"data_analyse_number", [@"客流分析" S]],
                         @[@"data_analyse_customer", [@"客户画像分析" S]],
                         @[@"data_analyse_success", [@"成交分析" S]],
                         @[@"data_analyse_fail", [@"战败分析" S]]],
                       @[@[@"data_analyse_medium", [@"网媒分析" S]]]
                       ];
    }
    return _dataArray;
}
@end
